﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using 自制数学工具;
using Point = 自制数学工具.Point;

namespace 计算搭接接头坐标点
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // 准备容器
            Point A = new Point();
            Point B = new Point();
            double AC = 0, d = 0, L = 0;
            // 接收数据
            try
            {
                char[] speraters = new char[] { ',', '，', '(', ')', '（', '）' };
                string[] PointA = txtPointA.Text.Split(speraters, StringSplitOptions.RemoveEmptyEntries);
                A = new Point(double.Parse(PointA[0]), double.Parse(PointA[1]));
                string[] PointB = txtPointB.Text.Split(speraters, StringSplitOptions.RemoveEmptyEntries);
                B = new Point(double.Parse(PointB[0]), double.Parse(PointB[1]));
                AC = double.Parse(txtAC.Text.Trim());
                d = double.Parse(txtd.Text.Trim());
                L = double.Parse(txtL.Text.Trim());
            }
            catch (Exception)
            {
                MessageBox.Show("参数格式异常");
            }

            // 进行计算
            try
            {
                Point C = Maths.GetExtendPoint(B, A, -AC);
                double Length = Math.Sqrt(d * d + L * L);
                Point D = Maths.GetExtendPoint(A, C, -Length / 2);
                Point F = Maths.GetExtendPoint(A, C, Length / 2);
                double Rotation = Math.Atan2(d, L) * 180 / Math.PI;
                Point E = Maths.GetRotationPoint(D, C, Rotation, L);
                Point G = Maths.GetRotationPoint(F, C, Rotation, L);
                // 填充数据
                txtPointD.Text = $"{D.X},{D.Y}"; 
                txtPointE.Text = $"{E.X},{E.Y}";
                txtPointF.Text = $"{F.X},{F.Y}";
                txtPointG.Text = $"{G.X},{G.Y}";
            }
            catch (Exception) { MessageBox.Show(e.ToString()); }
            
        }
    }
}
